import { defineStore } from 'pinia'
import { getC1Data, getC2Data, getC3Data } from '@/api/product/attr'
import type { categoryState } from '../types/type'
import type { CategoryResponseData } from '@/api/product/attr/type'
const useCategoryStore = defineStore('categoryStore', {
  state: (): categoryState => {
    return {
      c1Id: '2',
      c2Id: '13',
      c3Id: '61',
      c1Arr: [],
      c2Arr: [],
      c3Arr: [],
    }
  },
  actions: {
    async getC1Data() {
      const res: CategoryResponseData = await getC1Data()
      if (res.code === 200) {
        this.c1Arr = res.data
      }
    },
    async getC2Data() {
      const res: CategoryResponseData = await getC2Data(this.c1Id)
      if (res.code === 200) {
        this.c2Arr = res.data
      }
    },
    async getC3Data() {
      const res: CategoryResponseData = await getC3Data(this.c2Id)
      if (res.code === 200) {
        this.c3Arr = res.data
      }
    },
  },
  getters: {},
})
export default useCategoryStore
